<?php
final class bankPluginFunctions
{
	public static function getBankAccountID($account)
	{
		return sprintf("%08d-%06d-%06d",$account['a_mem_id'],$account['a_random'],$account['account_id']);
	}
	
	public static function buildBankAccountID($accountID, $randomNumber, $memberID)
	{
		return sprintf("%08d-%06d-%06d",$memberID,$randomNumber,$accountID);
	}
	
	public static function getBankAccoutParts($bankAccountID)
	{
		list($member_id,$random,$account_id) = explode("-",$bankAccountID);
		$ids = array();
		$ids['member'] = intval(ltrim($member_id,"0"));
		$ids['random'] = intval(ltrim($random,"0"));
		$ids['account'] = intval(ltrim($account_id,"0"));
		
		return $ids;
	}
	
	public static function logTransaction($account_id, $action, $amount, $balance, $fee, $time = -1)
	{
		ipsRegistry::DB()->insert('market_bank_transactions',array(
																	'l_account_id' => $account_id,
																	'l_timestamp' => $time == -1 ? IPS_UNIX_TIME_NOW : $time,
																	'l_ip_address' => ips_MemberRegistry::instance()->ip_address,
																	'l_action' => $action,
																	'l_amount' => $amount,
																	'l_balance' => $balance,
																	'l_fee' => $fee,
								)								);
	}
}
?>